package fr.noe.amicaleloisirs.concours.utils;

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;

public class Logger {

	private static Logger instance = null;

	public static Logger get() {
		if (instance == null)
			instance = new Logger();
		return instance;
	}

	public final Element getAppletElement() {
		return Document.get().getElementById(Constants.LOG_APPLET_ID);
	}

	/**
	 * @Deprecated Use "logInfo" instead
	 */
	private final native boolean logInfoApplet(String text) /*-{
		var obj = this;
		var logApplet = obj.@fr.noe.amicaleloisirs.concours.utils.Logger::getAppletElement()();
		return logApplet.log(text);
	}-*/;
	
	private final native boolean logInfo(String text) /*-{
		console.log(text);
		return true;
	}-*/;

	public final boolean logWithClass(String className, String s) {
		if (Constants.IS_LOGGING)
			//logInfoApplet(className + " > " + s);
			logInfo(className + " > " + s);
		return true;
	}
}

